var db=require("../db/db.js");
var express=require("express");
var router=require('vue-router')
var app=express();
var bodyParser=require("body-parser");
var qs=require("querystring")
const { request, response } = require("express");
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
var router=express.Router();
router.post("/myBlog/send",(request,response)=>{
    // new db.Msgbox(request.body).save().then(()=>{
    //     db.Msgbox.find().then(res=>{
    //         console.log(res)
    //     })
    // })

    var data='';
    request.on('data',function(chunk){
        data+=chunk;
    });
    request.on('end',function(){
        data=decodeURI(data);
        var dataObject=JSON.parse(data);
        //console.log(dataObject);
        response.send(dataObject);
        new db.Msgbox(dataObject).save()
    });

    
})
router.post('/myBlog/myAccount',(request,response)=>{
 
    var data='';
    request.on('data',function(chunk){
        data+=chunk;
    });
    request.on('end',function(){
        data=decodeURI(data);
        var dataObject=JSON.parse(data);
        //console.log(dataObject);
        db.Msgbox.find(dataObject).then(res=>{
            //console.log(res) 
            response.send(res)
        })
        // response.send(dataObject);
        // new db.Msgbox(dataObject).save()
    });  
})
router.get("/myBlog/deleteMsg",(request,response)=>{
    db.Msgbox.deleteOne(request.query).then(()=>{
       db.Msgbox.find({geter:request.query.geter}).then(res=>{
           response.send(res)
            //console.log(res)
       })
       
    })
    console.log(request.query)
})

module.exports=router;